using FluentNHibernate.Mapping;
using Munim.Fame.Core.DomainModels;

namespace Munim.Fame.DataAccess.NHibernate.Mapping
{
    public sealed class CategoryMap : ClassMap<Category>
    {
        public CategoryMap()
        {
            Id(c => c.Id);
            Map(c => c.Name);
            HasManyToMany(c => c.Parents)
                .ParentKeyColumn("Id")
                .ChildKeyColumn("ParentId")
                .Table("CategoryHierarchyMap")
                .ExtraLazyLoad();
            HasManyToMany(c => c.Medias).Cascade.All().Table("CategoryMap").ExtraLazyLoad();
        }
    }
}